#include <stdio.h>
#include <stdlib.h>

// 需要使用控制台运行
// E:\Desktop\data_struct\EXE\count.exe G:\a.txt
//                                     -文件名
int main(int argc, char *argv[])
{
    /*******************code*******************/
    int ch;
    FILE *fp, *fout;
    unsigned long count = 0;
    if (argc != 3)
    {
        printf("Usage :%s filename\n", argv[0]);
        // EXIT_FAILURE 退出 失败
        // Argument values for exit()
        // #define EXIT_SUCCESS 0   exit(0)==return 0==exit(EXIT_SUCCESS)
        // #define EXIT_FAILURE 1
        exit(EXIT_FAILURE);
    }
    if ((fp = fopen(argv[1], "r")) == NULL)
    {
        printf("can not open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    if ((fout = fopen(argv[2], "a")) == NULL)
    {
        printf("can not open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }

    // EOF 文件结束位置
    while ((ch = getc(fp)) != EOF)
    {
        // == putchar(ch);
        // 输出到 fout 中
        putc(ch, fout);
        count++;
    }
    fclose(fp);
    fclose(fout);
    printf("\nFile %s has %lu characters", argv[1], count);
    /******************************************/
    printf("\n\n****************************\n");
    printf("Press Enter key to continue\n");
    getchar();
    return 0;
    /******************************************/
}
